<?php
/**
 * Created by Shijie Liu. 2017/6/18
 * 登陆验证模块
 */
    include("DB_util.php");
    $db = new DB_util();

    $phone = $_GET['user'];
//    $phone = "Test";
    echo login($phone);


    function login($user_id)
    {
        $db = new DB_util();
        //查密码
        $sql = "SELECT user_psd From user WHERE user_id = '$user_id';";
        $result = $db->queryDB($sql);

        if ($result) {
            $psd_r = $result->fetch_row()[0];
            $state = null;

            if (mysqli_num_rows($result) >= 1) {  //非空数据
                //比对密码
                if ($_GET["psd"] == $psd_r) {
                    setcookie("user_login", $user_id, time() + 3600,"/");
                    $state = "ok";  //匹配成功
                } else {
                    $state = "wrong";
                }
            } else {
                $state = "unregistered";  //查询为空，未注册
            }
        } else {
            $state = "fail";  //查询失败
        }
        return $state;
    }

